package com.jswlw.controller.distributor;

import com.jswlw.controller.BaseController;
import com.jswlw.entity.biz.*;
import com.jswlw.service.biz.*;
import com.jswlw.web.manager.SessionDistributorManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 吴维斌 E-mail:wuweibin0817@163.com
 * @version 创建时间：${date} ${time}
 */
@Controller
@RequestMapping("/distributor")
public class DistributorIndexController extends BaseController {

    @Autowired
    OrderInfoService orderInfoService;
    @Autowired
    RepairInfoService repairInfoService;
    @Autowired
    BookInfoService bookInfoService;
    @Autowired
    FeedBackService feedBackService;
    @Autowired
    DistributorService distributorService;
    @Autowired
    DevInfoService devInfoService;
    @Autowired
    DistributionRecordService recordService;

    @RequestMapping("index")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("level", SessionDistributorManager.getCurrentUser().getLevel());
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setDistributorIds(SessionDistributorManager.getCurrentUser().getChildrenIds());
        modelAndView.addObject("orderCount", orderInfoService.queryList(orderInfo).size());

        BookInfo bookInfo = new BookInfo();
        bookInfo.setDistributorIds(SessionDistributorManager.getCurrentUser().getChildrenIds());
        modelAndView.addObject("bookInfoCount", bookInfoService.queryList(bookInfo).size());

        FeedBack feedBack = new FeedBack();
        feedBack.setDistributorIds(SessionDistributorManager.getCurrentUser().getChildrenIds());
        modelAndView.addObject("feedBackCount", feedBackService.queryList(feedBack).size());

        DevInfo devInfoFilter = new DevInfo();
        devInfoFilter.setDistributorIds(SessionDistributorManager.getCurrentUser().getChildrenIds());
        modelAndView.addObject("devInfoCount", devInfoService.queryList(devInfoFilter).size());

        RepairInfo repairInfo = new RepairInfo();
        repairInfo.setDistributorIds(SessionDistributorManager.getCurrentUser().getChildrenIds());
        modelAndView.addObject("repairInfoCount", repairInfoService.queryList(repairInfo).size());

        Distributor distributor2 = new Distributor();
        distributor2.setLevel(2);
        modelAndView.addObject("distributor2Count", distributorService.queryList(distributor2).size());

        Distributor distributor3 = new Distributor();
        distributor3.setLevel(3);
        distributor3.setParentId(SessionDistributorManager.getCurrentUser().getDistributorId());
        modelAndView.addObject("distributor3Count", distributorService.queryList(distributor3).size());


        modelAndView.setViewName("/distributor/index");
        return modelAndView;
    }
}
